package com.work.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @Author: 星川
 * @Date: 2023/06/08/20:05
 * @Description:
 */
public class VerifyCodeUtil {
    public static final Map<String, Integer> verificationCodeMap = new HashMap<>();

    /**
     * 生成4位随机验证码
     * @return
     */
    public static int generateVerifyCode(String phoneNumber) {
        //生成验证码
        Random random = new Random();
        int verifyCode = random.nextInt(9000) + 1000;
        //保存验证码
        storeVerificationCode(phoneNumber,verifyCode);//(13838383,1234)
        return verifyCode;
    }

    /**
     * 存储验证码
     * @param phoneNumber
     * @param code
     */
    public static void storeVerificationCode(String phoneNumber, int code) {
        verificationCodeMap.put(phoneNumber, code);
    }
}
